import {IAttribute, IFragmentResult, InnerVarying, IUniform, IVarying, Program} from "./Program";
import {Vector4} from "../math/Vector4";
import {Vector3} from "../math/Vector3";
import {Matrix4} from "../math/Matrix4";
import {Vector2} from "../math/Vector2";
import {Texture} from "../asserts/Texture";
export interface Varying  extends IVarying {
    vUv: Vector2;
}
export interface Attribute extends IAttribute  {
    aPosition: Vector3;
    aUv: Vector2;
    // aNormal: Vector3;
}
export interface Uniform extends IUniform {
    uMVPMatrix: Matrix4;
    uTexture: Texture,
    // uLightDire: Vector3;
}
export class TextureProgram extends Program<Attribute, Uniform, Varying> {
    vertexShader(attribute: Attribute, uniform: Uniform): InnerVarying & Varying {
        const {aPosition, aUv} = attribute;
        const {uMVPMatrix} = uniform;
        // console.log('aUv: ', aUv.toString());
        // console.log('aPosition: ', aPosition.toString());
        return {
            vPosition: aPosition.appliedMatrix4(uMVPMatrix),
            vUv: aUv
        }
    }
    fragmentShader(varying: InnerVarying & Varying, uniform: Uniform): IFragmentResult {
        const {vUv} = varying;
        const {uTexture} = uniform;
        // console.log('vUv', vUv.toString());
        // console.log('color',  uTexture.sample(vUv.x,vUv.y).toString());

        return {
            color: uTexture.sample(vUv.x,vUv.y),
            discard: false
        };
    }
}